﻿#include "CheckBoxPropertyEditEntry.h"
#include <QCheckBox>

#include "BooleanEditEntry.h"

#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(CheckBox)

struct CheckBoxPropertyEditEntry::CheckBoxPropertyEditEntryPrivate {
    QPointer<QCheckBox> object;
    QPointer<BooleanEditEntry> entryTristate;
};

CheckBoxPropertyEditEntry::~CheckBoxPropertyEditEntry() { }

CheckBoxPropertyEditEntry::CheckBoxPropertyEditEntry(QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new CheckBoxPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

void CheckBoxPropertyEditEntry::setObject(void *object) {
    p->object = static_cast<QCheckBox*>(object);
}

void CheckBoxPropertyEditEntry::onTick() {
    if(!p->object || !isVisible()) {
        return ;
    }

    p->entryTristate->setValue(p->object->isTristate());
}

void CheckBoxPropertyEditEntry::initUi() {
    p->entryTristate = new BooleanEditEntry;
    appendChildEntry(p->entryTristate);
}

void CheckBoxPropertyEditEntry::retranslateUi() {
    setTitle(tr("QCheckBox"));
    p->entryTristate->setTitle(tr("tristate"));
}
